// -----------------------------------------------------------------------
// <copyright file="NodeType.cs" company="VDC-IT" author="LTDUC">
//      Copyright (c) VDC-IT. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace VDC.VONE.ENTITIES
{
    using System;
    using System.Collections.Generic;
    using System.Data.SqlClient;
    using AdCom.Utility;
    using VDC.COMMON;

    /// <summary>
    /// Class Date
    /// </summary>
    public class NodeType
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="NodeType" /> class
        /// </summary>
        public NodeType()
        {
            this.NodeTypeId = 0;
            this.Code = string.Empty;
            this.Name = string.Empty;
        }

        /// <summary>
        /// Gets or sets NodeTypeId
        /// </summary>
        public int NodeTypeId { get; set; }

        /// <summary>
        /// Gets or sets Code
        /// </summary>
        public string Code { get; set; }

        /// <summary>
        /// Gets or sets Name
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// Gets Nodes
        /// </summary>
        public IList<Node> Nodes
        {
            get
            {
                try
                {
                    IList<Node> lstNode = new List<Node>();
                    var reader = SqlDataHelper.ExecuteReader(string.Format(Constants.StorepProcedure.VOneNodeGetByNodeTypeId, this.NodeTypeId));
                    while (reader.Read())
                    {
                        Node node = new Node();
                        if (!reader.IsDBNull(0))
                        {
                            node.NodeId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            node.NodeTypeId = reader.GetInt32(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            node.Code = reader.GetString(2);
                        }

                        if (!reader.IsDBNull(3))
                        {
                            node.Name = reader.GetString(3);
                        }

                        lstNode.Add(node);
                    }

                    reader.Close();
                    reader.Dispose();
                    return lstNode;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }
    }
}
